package com.Wu.costomer.controller;

import com.Wu.costomer.service.CustomerService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/register.do")
public class CurstomerRegisterController extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        CustomerService service = new CustomerService();
        boolean result = service.register(username, password);
        if (result) {
            //注册成功进入首页
            req.getRequestDispatcher("/login.jsp").forward(req, resp);
        } else {
            //注册失败后回到注册页面
            req.getRequestDispatcher("/register.jsp").forward(req, resp);
        }
    }
}
